﻿using System;
using System.Collections.Generic;
using System.Windows.Input;

namespace Microsoft.Popfly.GameCreator.GameEngine.Events
{
    public static class KeyEventCheckerFactory
    {
        public static IEventChecker CreateKeyEventChecker(Game game, Data.KeyEventInfo eventInfo)
        {
            List<Key> keys = new List<Key>();

            foreach (KeyValuePair<string, Data.KeyEventInfo.KeyInfo> kvp in eventInfo.Keys)
            {
                keys.Add((Key) kvp.Value.keyCode);
            }
            switch (eventInfo.KeyType)
            {
                case null: 
                case "whileDown":
                    return new WhileKeyDownEventChecker(game, keys);
                case "down":
                    return new KeyDownEventChecker(game, keys);
                case "up":
                    return new KeyUpEventChecker(game, keys);

                default:
                    throw new NotImplementedException(
                        "CreateKeyEventChecker does not know how to handle the key event type '" + 
                        eventInfo.KeyType + "'."
                        );
            }

        }
    }
}
